<script setup>
//定义响应式数组
import {ref} from "vue";

const productArr = ref(
    [
      {title:"葡萄",price:10,num:100},
        {title:"苹果",price:20,num:100},
        {title:"香蕉",price:30,num:100},
    ]
)
const del = (index) => {
  if (confirm("是否删除")){
    productArr.value.splice(index,1)
  }
}
</script>

<template>
<h1>这是D</h1>
  <ul>
    <li v-for="item in 3">阿巴{{item}}</li>
  </ul>
  <hr>
  <ul v-for="item in 3">
    <li>Hello{{item}}</li>
    <li>Hello{{item}}</li>
    <li>Hello{{item}}</li>
  </ul>

  <table border="1">
    <tr>
      <th>商品编号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品数量</th>
      <th>操作</th>
    </tr>
    <tr v-for="(p,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{p.title}}</td>
      <td>{{p.price}}</td>
      <td>{{p.num}}</td>
      <td><button @click="del( index)">删除</button></td>
    </tr>
  </table>
</template>

<style scoped>

</style>